#ifndef __DRV_UART_H__
#define __DRV_UART_H__

#include "common_config.h"

#include <stdbool.h>
#include <stdint.h>

typedef void (*uart_callback_f)(uint32_t instance, void *param);

/**
 * @brief UART实例枚举
 *
 */
typedef enum
{
    UART_INSTANCE_UART0_0 = 0U,  /*< ! UART0实例0, Tx: PC3, Rx: PC2, FUN4 */
    UART_INSTANCE_UART0_1 = 1U,  /*< ! UART0实例1, Tx: PB1, Rx: PB0, FUN4 */
    UART_INSTANCE_UART0_2 = 2U,  /*< ! UART0实例2, Tx: PC9, Rx: PC8, FUN5 */
    UART_INSTANCE_UART1_0 = 3U,  /*< ! UART1实例0, Tx: PE5, Rx: PE4, FUN4 */
    UART_INSTANCE_UART1_1 = 4U,  /*< ! UART1实例1, Tx: PA3, Rx: PA2, FUN5 */
    UART_INSTANCE_UART1_2 = 5U,  /*< ! UART1实例2, Tx: PA1, Rx: PA0, FUN3 */
    UART_INSTANCE_UART1_3 = 6U,  /*< ! UART1实例3, Tx: PA11, Rx: PA10, FUN6 */
    UART_INSTANCE_UART2_0 = 7U,  /*< ! UART2实例0, Tx: PD1, Rx: PD0, FUN4 */
    UART_INSTANCE_UART2_1 = 8U,  /*< ! UART2实例1, Tx: PD7, Rx: PD6, FUN3 */
    UART_INSTANCE_UART2_2 = 9U,  /*< ! UART2实例2, Tx: PC9, Rx: PC8, FUN4 */
    UART_INSTANCE_UART2_3 = 10U, /*< ! UART2实例3, Tx: PC5, Rx: PC4, FUN5*/
    UART_INSTANCE_MAX,
} snf_uart_instance_e;

/**
 * @brief UART配置结构体
 *
 */
typedef struct
{
    snf_uart_instance_e instance;          /*< ! UART实例 */
    uint32_t            baud_rate;         /*< ! 波特率 */
    uart_callback_f     rx_callback;       /*< ! UART-Rx回调函数 */
    void               *rx_callback_param; /*< ! UART-Rx回调函数参数 */
} snf_uart_config_t;

result_e snf_drv_uart_init(const snf_uart_config_t *uart_config);
result_e snf_drv_uart_send(snf_uart_instance_e instance, const uint8_t *data, uint32_t length);
result_e snf_drv_uart_receive(snf_uart_instance_e instance, uint8_t *data, uint32_t length);

#endif
